package logic

import (
	"context"
	"doctor-medicine-system/model/mysql"

	"doctor-medicine-system/goods/goods"
	"doctor-medicine-system/goods/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddGoodsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddGoodsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddGoodsLogic {
	return &AddGoodsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddGoodsLogic) AddGoods(in *goods.AddGoodsRequest) (*goods.AddGoodsResponse, error) {
	// todo: add your logic here and delete this line
	data := mysql.Goods{
		Name:   in.Name,
		Size:   in.Size,
		Form:   in.Form,
		Eat:    in.Eat,
		Use:    in.Use,
		Moment: in.Moment,
	}

	if err := data.AddGoods(mysql.DB); err != nil {
		return nil, err
	}
	return &goods.AddGoodsResponse{
		GoodId: int64(data.ID),
	}, nil
}
